package com.example.demo4activemq

import org.junit.Test
import org.junit.runner.RunWith
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.jms.core.JmsTemplate
import org.springframework.test.context.junit4.SpringRunner

@RunWith(SpringRunner)
@SpringBootTest
class Demo4activemqApplicationTests {

    @Autowired
    JmsTemplate jmsTemplate

    @Test
    void contextLoads() {
        def count = 0

        while (count < 50) {
            println "Sending an email message."
            jmsTemplate.convertAndSend("demo.mailbox", new Email("info@example.com", "Hello, ${count + 1}"))
            count++
            sleep 1000
        }

        assert count == Receiver.counter.get()
    }

}
